<!DOCTYPE HTML>
<html lang="en">
<head>
<title>WinActivate - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The WinActivate command activates the specified window." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>WinActivate</h1>

<p>Activates the specified window.</p>

<pre class="Syntax"><span class="func">WinActivate</span> <span class="optional">, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>
<h2>Parameters</h2>
<dl>

  <dt>WinTitle</dt>
  <dd><p>A window title or other criteria identifying the target window. See <a href="../misc/WinTitle.htm">WinTitle</a>.</p></dd>

  <dt>WinText</dt>
  <dd><p>If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if <a href="DetectHiddenText.htm">DetectHiddenText</a> is ON.</p></dd>

  <dt>ExcludeTitle</dt>
  <dd><p>Windows whose titles include this value will not be considered.</p></dd>

  <dt>ExcludeText</dt>
  <dd><p>Windows whose text include this value will not be considered.</p></dd>

</dl>

<h2>Remarks</h2>
<p>When an inactive window becomes active, the operating system also makes it foremost (brings it to the top of the stack). This does not occur if the window is already active.</p>
<p>If the window is minimized and inactive, it is automatically restored prior to being activated. <span class="ver">[v1.1.20+]:</span> If <em>WinTitle</em> is the letter "A" and the other parameters are omitted, the active window is restored. <span class="ver">[v1.1.28.02+]:</span> The window is restored even if it was already active.</p>
<p>Six attempts will be made to activate the target window over the course of 60ms. If all six attempts fail, WinActivate automatically sends <code>{Alt 2}</code> as a workaround for possible restrictions enforced by the operating system, and then makes a seventh attempt. Thus, it is usually unnecessary to follow WinActivate with <a href="WinWaitActive.htm">WinWaitActive</a> or <a href="WinActive.htm">IfWinNotActive</a>.</p>
<p>In general, if more than one window matches, the topmost matching window (typically the one most recently used) will be activated. If the window is already active, it will be kept active rather than activating any other matching window beneath it. However, if the active window is moved to the bottom of the stack with <a href="WinSet.htm#Bottom">WinSet Bottom</a>, some other window may be activated even if the active window is a match.</p>
<p><a href="WinActivateBottom.htm">WinActivateBottom</a> activates the bottommost matching window (typically the one least recently used).</p>
<p><a href="GroupActivate.htm">GroupActivate</a> activates the next window that matches criteria specified by a window group.</p>
<p><span class="ver">[v1.1.20+]:</span> If the active window is hidden and <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> is turned off, it is never considered a match. Instead, a visible matching window is activated if one exists.</p>
<p>When a window is activated immediately after the activation of some other window, task bar buttons might start flashing on some systems (depending on OS and settings). To prevent this, use <a href="_WinActivateForce.htm">#WinActivateForce</a>.</p>
<p>Window titles and text are case sensitive. Hidden windows are not detected unless <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> has been turned on.</p>
<p><strong>Known issue:</strong> If the script is running on a computer or server being accessed via remote desktop, WinActivate may hang if the remote desktop client is minimized. One workaround is to use commands which don't require window activation, such as <a href="ControlSend.htm">ControlSend</a> and <a href="ControlClick.htm">ControlClick</a>. Another possible workaround is to apply the following registry setting on the local/client computer:</p>
<pre><em>; Change HKCU to HKLM to affect all users on this system.</em>
RegWrite REG_DWORD, HKCU, Software\Microsoft\Terminal Server Client
    , RemoteDesktop_SuppressWhenMinimized, 2</pre>

<h2>Related</h2>
<p><a href="WinActivateBottom.htm">WinActivateBottom</a>, <a href="_WinActivateForce.htm">#WinActivateForce</a>, <a href="SetTitleMatchMode.htm">SetTitleMatchMode</a>, <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a>, <a href="../misc/WinTitle.htm#LastFoundWindow">Last Found Window</a>, <a href="WinExist.htm">WinExist() / IfWinExist</a>, <a href="WinActive.htm">WinActive() / IfWinActive</a>, <a href="WinWaitActive.htm">WinWaitActive</a>, <a href="WinWait.htm">WinWait</a>, <a href="WinWaitClose.htm">WinWaitClose</a>, <a href="WinClose.htm">WinClose</a>, <a href="GroupActivate.htm">GroupActivate</a>, <a href="WinSet.htm">WinSet</a></p>
<h2>Examples</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>if WinExist("Untitled - Notepad")
    WinActivate <em>; use the window found above</em>
else
    WinActivate, Calculator</pre>
</div>

</body>
</html>
